package cn.cvs.service.impl;

import cn.cvs.dao.SysRoleMapper;
import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: zwt
 * @Date: 2021/11/12 - 11 - 12 - 11:14
 * @Description: cn.cvs.service
 * @version: 1.0
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;

    @Resource
    RedisTemplate<Object,Object> redisTemplate;

    @Override
    public List<SysRole> queryAllRoles() {
        Object queryAllRoles = redisTemplate.opsForValue().get("queryAllRoles");
        if(queryAllRoles!=null){
            return (List<SysRole>)queryAllRoles;
        }
        List<SysRole> sysRoles = sysRoleMapper.queryAll();
        if(sysRoles!=null){
            redisTemplate.opsForValue().set("queryAllRoles",sysRoles);
        }
        return sysRoles;
    }
}
